package com.graduation.project.controller.system;

import com.graduation.project.entity.dto.menu.SaveOrUpdateMenuDTO;
import com.graduation.project.entity.dto.menu.ListMenuDTO;
import com.graduation.project.entity.dto.UpdateStatusDTO;
import com.graduation.project.service.system.MenuManagementService;
import com.graduation.project.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 卑微小峰
 * @date 2022/11/05
 * 权限管理控制类
 */
@RestController
@RequestMapping("/menu_management")
public class MenuManagementController {

    @Autowired
    private MenuManagementService menuManagementService;

    /**
     * 新增菜单
     * @param input 新增/修改菜单输入类
     * @return ResultUtil
     */
    @PostMapping("/post/addMenu")
    public ResultUtil<?> addMenu(@RequestBody SaveOrUpdateMenuDTO input) {
        return menuManagementService.addMenu(input);
    }

    /**
     * 修改菜单
     * @param input 新增/修改菜单输入类
     * @return ResultUtil
     */
    @PutMapping("/put/updateMenu")
    public ResultUtil<?> updateMenu(@RequestBody SaveOrUpdateMenuDTO input) {
        return menuManagementService.updateMenu(input);
    }

    /**
     * 根据id修改状态
     * @param input 修改状态输入类
     * @return ResultUtil
     */
    @PutMapping("/put/updateMenuStatusById")
    public ResultUtil<?> updateMenuStatusById(@RequestBody UpdateStatusDTO input) {
        return menuManagementService.updateMenuStatusById(input);
    }

    /**
     *
     * 删除菜单及其子项
     * @param id 选中id
     * @return
     */
    @DeleteMapping("/delete/deleteMenu")
    public ResultUtil<?> deleteMenu(@RequestParam("id") Long id) {
        return menuManagementService.deleteMenu(id);
    }

    /**
     * 菜单列表
     * @param input 查询菜单列表输入类
     * @return ResultUtil
     */
    @PostMapping("/post/listMenuByCondition")
    public ResultUtil<?> listMenuByCondition(@RequestBody ListMenuDTO input) {
        return menuManagementService.listMenuByCondition(input);
    }

    /**
     * 获取弹窗父级菜单下拉数据
     * @return ResultUtil
     */
    @GetMapping("/get/listParentMenu")
    public ResultUtil<?> listParentMenu() {
        return menuManagementService.listParentMenu();
    }
}
